<template>
  <j-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="分配模式">
          <a-radio-group
            v-model="salesModel">
            <a-radio value="1" d>平均分配</a-radio>
            <a-radio value="2">指定销售</a-radio>
          </a-radio-group>
        </a-form-item>  
        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="分配给：" v-show="salesModel==2">
            <j-dict-select-tag v-decorator="['userId', { rules: [{ required: true, message: '请选择用户!' }]}]"
             placeholder="请选择用户" :triggerChange=true dictCode="sys_user,realname,id,sales=1 "/>
        </a-form-item>
      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>
import { httpAction } from '@/api/manage'
import pick from 'lodash.pick'
import moment from 'moment'
import JDictSelectTag from '@/components/dict/JDictSelectTag.vue'
import JAreaLinkage from '@comp/jeecg/JAreaLinkage'
import JSelectMultiUser from '@/components/jeecgbiz/JSelectMultiUser'
import JSelectUserByDep from '@/components/jeecgbiz/JSelectUserByDep'

export default {
  name: 'ClueAppoint',
  components: {
    JDictSelectTag,
    JAreaLinkage,
    JSelectUserByDep,
    JSelectMultiUser,
  },
  data() {
    return {
      salesModel: '1',
      userId: '',
      title: '操作',
      visible: false,
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },

      confirmLoading: false,
      form: this.$form.createForm(this),
      validatorRules: {},
      url: {
        add: '/crm/clue/add',
        edit: '/crm/clue/edit',
      },
    }
  },
  created() {},
  methods: {
    edit(record) {
      this.visible = true
      this.salesModel='1'
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      if(this.salesModel==1){
        httpAction("/crm/clue/appointAll", '', "post")
        .then((res) => {
          if (res.success) {
            this.$message.success('操作成功')
          } else {
            this.$message.warning(res.message)
          }
        })
      }else{
        this.userId = this.form.getFieldValue('userId')
        if(this.userId==''){
          this.$message.warning('请选择用户')
          return ;
        }
        let param={userId:this.userId}
        httpAction("/crm/clue/appointAllUser", param, "post")
        .then((res) => {
          if (res.success) {
            this.$message.success('操作成功')
          } else {
            this.$message.warning(res.message)
          }
        })
      }
      
    },
    handleCancel() {
      this.close()
    },
  },
}
</script>

<style lang="less" scoped>
</style>